from operator import *
# print(lt(1, 2)) # a < b
# print(gt(10, 1)) # a > b
# print(le(1, 3)) # a <= b
# print(ge(10, 10)) # a >= b
# print(eq(10, 9)) # a == b
# print(ne(10,10)) # a != b

# print(and_(1, 1)) # a & b
# print(or_(1, 2)) # or_(a, b)
# print(xor(1, 2)) # a ^ b
# print(invert(1)) # ~ a
# a = [1, 2, 3]
# b = 3
# print(is_(a, b)) # a is b
# print(is_not(a, b)) # a is not b
# print(truth(a)) # obj

'''
加	add(a ,b)	a + b
除	truediv(a, b)	a / b
乘	mul(a, b)	a * b
减	sub(a, b)	a - b
幂	pow(a, b)	a ** b
负数	neg(a)	- a
正数	pos(a)	+ a
取模	mod(a, b)	a % b

字符串拼接	concat(seq1, seq2)	seq1 + seq2
包含	contains(seq, obj)	obj in seq
索引赋值	setitem(obj, i, v)	obj[i] = v
索引删除	delitem(obj, i)	del obj[i]
索引取值	getitem(obj, i)	obj[i]
切片赋值	setitem(seq, slice(i, j), values)	seq[i:j] = values
切片删除	delitem(seq, slice(i, j))	del seq[i:j]
切片取值	getitem(seq, slice(i, j))	seq[i:j]
格式化	mod(s, obj)	s % obj
'''

# attrgetter 类可以获取对象的属性用于 map(), stored() 操作
# class Student:
#     pass
#
#     def __init__(self, name, score):
#         self.name = name
#         self.score = score
#
#     def __repr__(self): # print 打印
#         return '%s(name=%r,score=%r)' % (self.__class__.__name__, self.name, self.score)
#
# if __name__ == '__main__':
#     students = [Student("zhangSan", 89),
#                 Student("liSi", 60),
#                 Student("wangWu", 70),
#                 Student("xiaoMing", 100)]
#
#
#     print("按照【分数】排序: ")
#     print(sorted(students, key=attrgetter('score'), reverse=True))
#
#     g = attrgetter("score") # 获取【分数】属性
#     vals = [g(i) for i in students]
#     print('获取分数属性：' + str(vals))

# itemgetter 类会返回一个可调用对象，传入多个对象则返回元组

print(itemgetter(3)('abcdefg'))
print(itemgetter(1, 3, 4)('abcdefg'))
print(itemgetter('name')({'name': 'liSi', 'age': 18}))
soldier = dict(rank='captain', name='dotterbart')
print(itemgetter('rank')(soldier))
inventory = [('apple', 8), ('banana', 2), ('pear', 7)]
getCount = itemgetter(1)
print(list(map(getCount, inventory)))
print(sorted(inventory, key = getCount))
